import httpFetch from 'share/httpFetch';
import {message} from "antd";
import config from "config";

const bufferServer = (context) => {
  context.setState({loading: true});
  const realmId = config.realmIds[location.host] || config.realmId;
  return {
    async getBufferData(params){
      try {
        const response = await httpFetch.get('/open/user/api/config/getBufferConfig?realmId='+realmId,params);
        return response;
      }catch (e) {
        dealWithErrorMes(e);
      }finally {
        context.setState({loading: false})
      }
    },
    async saveBufferData(params){
      try {
        const response = await httpFetch.post('/open/user/api/config/saveBufferConfig?realmId='+realmId,params);
        return response;
      }catch (e) {
        dealWithErrorMes(e);
      }finally {
        context.setState({loading: false})
      }
    },
  }
}

const dealWithErrorMes = (err) => {
  message.error(`error:${err.response.data.message}`);
}

export default bufferServer;
